package com.cxm.helper.config.web;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.collection.CollUtil;
import com.cxm.helper.enums.UserRoleEnum;
import com.cxm.helper.pojo.User;
import com.cxm.helper.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: chenximeng
 * @date: 2022/12/2 10:15
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    UserService userService;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return CollUtil.newArrayList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<String> list = CollUtil.newArrayList();
        Long id = Long.parseLong(String.valueOf(loginId));
        User loginUser = userService.getById(id);
        if (loginUser.getAdmin().equals(UserRoleEnum.ADMIN.getCode())) {
            list.add("admin");
        }
        return list;
    }
}
